﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace homeIMSClient.Model
{
    public class user
    {
        //private variables that store user information
        private int _userID;
        private string _userName;
        private string _password;
        private string _address;
        private string _city;
        private string _state;
        private string _zip;

        //public variable with list of assets
        public List<asset> assetList;

        //public varables that give access to change user information
        public int UserID
        {
            get{ return _userID; }
        }

        public string UserName
        {
            get { return _userName; }
            set { _userName = value; }
        }

        public string Password
        {
            get { return _password; }
            set { _password = value; }
        }

        public string Address
        {
            get { return _address; }
            set { _address = value; }
        }

        public string City
        {
            get { return _city; }
            set { _city = value; }
        }

        public string State
        {
            get { return _state; }
            set { _state = value; }
        }

        public string Zip
        {
            get { return _zip; }
            set { _zip = value; }
        }

        //constuctor will take in object and cast it as user
        public user(homeIMSRef.userInfo passedUser)
        {
            //instantiate assetList
            assetList = new List<asset>();

            //store userInfo
            hydrateUser(passedUser);

            //hydrate assets
            hydrateAssets(_userID);

        }

        //method used to retrieve and store user information
        private void hydrateUser(homeIMSRef.userInfo userInfo)
        {
            //hydrate private variables with user information
            _userID = userInfo.userID;
            _userName = userInfo.userName;
            _password = userInfo.password;
            _address = userInfo.address;
            _city = userInfo.city;
            _state = userInfo.state;
            _zip = userInfo.zip;
        }

        //method used to retrieve assets
        private void hydrateAssets(int userID)
        {
            //create assets and add to list
            //create service reference to use operation contract
            homeIMSRef.IhomeIMSService service = new homeIMSRef.IhomeIMSServiceClient();

            //run service method to fill variable.
            homeIMSRef.assetList allAssets = service.getUserAssets(userID);
            
            //for loop to create assets and store them in the list
            for (int i = 0; i < allAssets.userAssets.Count(); i++)
            {
                //for each assetIfno, create asset and store in list
                asset newAsset = new asset(allAssets.userAssets[i]);

                //store asset in list
                assetList.Add(newAsset);
            }
        }

        
    }
}
